/**
 * 
 */
package com.sangharsh.core.algo.location;

import java.text.DecimalFormat;
import java.text.Format;



/**
 * @author pradeep
 *
 */
public class Location implements Comparable<Location>{
	double latitude;
	double longitude;
	private Location(double latitude, double longitude) {
		super();
		this.latitude = latitude;
		this.longitude = longitude;
	}
	public double getLatitude() {
		return latitude;
	}
	public double getLongitude() {
		return longitude;
	}
	public static Location getLocation(double latitude, double longitude){
		return new Location(latitude, longitude);
	}
	public static Location getLocation(String str){
		//String string = str.substring(1, str.length()-1);
		String[] split = str.split(",");
		return Location.getLocation(new Double(split[0].trim()), new Double(split[1].trim()));
	}
	private Format formatter = new DecimalFormat("##.######");
	public String toString(){
		return formatter.format(this.latitude)+","+formatter.format(this.longitude);
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(latitude);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(longitude);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Location other = (Location) obj;
		if (Double.doubleToLongBits(latitude) != Double
				.doubleToLongBits(other.latitude))
			return false;
		if (Double.doubleToLongBits(longitude) != Double
				.doubleToLongBits(other.longitude))
			return false;
		return true;
	}
	@Override
	public int compareTo(Location other) {
		return new Double(LocationUtil.distance(this, other)).intValue();
	}
	
}
